/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package object;

import java.util.LinkedList;
import java.util.List;
import javax.media.opengl.GL;
import main.ScanConvert;

/**
 *
 * @author dheath
 */
public class Polygon implements Shape
{

    private List<Point> points;
    private Color color;
    private Point normal;
    private float distanceOrigin;
    
    public Polygon()
    {
        points = new LinkedList();
        this.color = new Color(1, 1, 1);
    }

    public Polygon(Color color)
    {
        points = new LinkedList();
        this.color = color;
    }

    public void multiplyMatrix(CS455Matrix m)
    {
        List<Point> newPoints = new LinkedList();

        CS455Matrix norm = new CS455Matrix(m.getArrayCopy());
        norm.set(0, 3, 0);
        norm.set(1, 3, 0);
        norm.set(2, 3, 0);
        norm.set(3, 0, 0);
        norm.set(3, 1, 0);
        norm.set(3, 2, 0);
        
        normal = norm.multiplyPoint(normal);
        normal.normalize();
        
        for (Point p : points)
        {
            Point n = m.multiplyPoint(p);

            Point nor = norm.multiplyPoint(p.getNormal());
            nor.normalize();
            n.setNormal(nor);
            newPoints.add(n);
        }
        points = newPoints;
    }

    public void addPointToPolygon(Point p)
    {
        getPoints().add(p);
    }

    public void draw(GL gl, Zbuffer zbuffer, Point lookFrom, Polygon world, boolean shading)
    {
        //gl.glColor3f(getColor().getRed(),getColor().getGreen(),getColor().getBlue());

        gl.glBegin(GL.GL_POINTS);

        ScanConvert scan = new ScanConvert();

        scan.scanConvert(this, world, gl, zbuffer, lookFrom, shading);

        /*for(Point p : getPoints())
        {
        // System.out.println("POINT: "+p.getX()+","+p.getY());
        gl.glVertex3f(p.getX(), p.getY(), 0);//*
        }*/

        gl.glEnd();
    }

    public List<Point> getPoints()
    {
        return points;
    }

    public void setPoints(List<Point> points)
    {
        this.points = points;
    }

    public Color getColor()
    {
        return color;
    }

    public void setColor(Color color)
    {
        this.color = color;
    }

    public Point getNormal()
    {
        return normal;
    }

    public void setNormal(Point normal)
    {
        this.normal = normal;
    }

    public float getDistanceOrigin()
    {
        return distanceOrigin;
    }

    public void setDistanceOrigin(float distanceOrigin)
    {
        this.distanceOrigin = distanceOrigin;
    }
}
